﻿using System.Collections.Generic;
using System.Windows.Controls;
using WPF_CAD.Algorithms;
using WPF_CAD.Model;
using WPF_CAD.Common;


namespace WPF_CAD.Strategy
{ 
    public class LineToolStrategy : StrategyBase
    {
        public LineToolStrategy(IFigure figure) : base(figure)
        {}

        public override IFigure PerformMouseLeftClicDownEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures)
        {
            ClickCount++;
            if (ClickCount == 2)
            {
                var lineRepresentation = BressenhamLine.GetLineRepresentation(Figure.InitialPoint, point);

                foreach (var pointInLine in lineRepresentation)
                {
                    Figure.PointsCollection.Add(pointInLine);
                }

                FigureDrawer.DrawFigure(canvas, Figure);
                return CloseFigureDrawing();
            }
            ValidateFigureIsNew<Line>();
            Figure.PointsCollection.Add(point);
            return Figure;
        }

        public override IFigure PerformMouseRightClicDownEvent(Canvas canvas, IPoint point, IEnumerable<IFigure> figures)
        {
            ValidateFigureIsNew<Line>();
            return Figure;
        }
    }
}
